package com.tedu.day02.test;

/**
 *
 * Object 类 equals方法：比较两个对象是否相等
 * 两个China类，比较两个China类是否相等
 * equals建议重写：修改其判断规则，中国：市，县
 *
 */
class China{
    public String city;
    public String county;
//判断两个中国的县市是否相等
    public boolean equals(Object o) {
        //1.参数【Object】强转China对象[引用]
        China china=(China)o;
        //2.判断市县是否相等
        boolean c=this.city.equals(china.city);
        boolean y=this.city.equals(china.county);
        //3。弹出
        return c&&y;
    }
}
public class 对象对比 {
    public static void main(String[] args) {
        China c1=new China();
        China c2=new China();
        System.out.println(c1.toString());
        System.out.println(c2.toString());
        System.out.println(c1.equals(c2));//默认对比地址值
    }
}
